/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ing.sisval.gui.control;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.ing.sisval.be.BEComplementario;
import org.ing.sisval.be.BEDepreciacion;

import org.ing.sisval.be.BEValcomplementario;
import org.ing.sisval.be.BEValuacionComplementario;
import org.ing.sisval.bl.BLComplementario;
import org.ing.sisval.bl.BLValcomplementario;
import org.ing.sisval.bl.BLValuacionComplementario;
import org.ing.sisval.gui.JFPrincipal;
import org.ing.sisval.gui.control.model.ModeloComplementario;
import org.ing.sisval.gui.control.model.ModeloComplementarioAsignado;
import org.ing.sisval.util.UtilDepreciacion;
import org.rx.cr.gui.JInternalFrameUC;
import org.rx.cr.util.Utilitarios;
import static org.rx.cr.util.Utilitarios.addCharacterValidatorEvent;
import static org.rx.cr.util.Utilitarios.addEnterDoclickEvent;
import static org.rx.cr.util.Utilitarios.alinearDatosColumnaTablaCentro;
import static org.rx.cr.util.Utilitarios.formateaAnchoColumnaTabla;

/**
 *
 * @author Mysham
 */
public class JIFValuacionComplementaria extends JInternalFrameUC {

    JFPrincipal parent;
    BEValuacionComplementario be;
    BLValuacionComplementario bl;
    ModeloComplementario modeloComplementario;
    ModeloComplementarioAsignado modeloComplementarioAsignado;

    BEComplementario beComplementario;
    BLComplementario blComplementario;

    BEValcomplementario beValcomplementario;
    BLValcomplementario blValcomplementario;

    UtilDepreciacion utilDepreciacion;

    /**
     * Creates new form JIFValuacionComplementaria
     */
    public JIFValuacionComplementaria(JFPrincipal parent) {
        initComponents();
        this.parent = parent;
        modeloComplementario = new ModeloComplementario();
        jtComplementario.setModel(modeloComplementario);

        modeloComplementarioAsignado = new ModeloComplementarioAsignado();
        jtComplementarioAsignado.setModel(modeloComplementarioAsignado);

        bl = new BLValuacionComplementario(parent.getConf());
        blComplementario = new BLComplementario(parent.getConf());
        blValcomplementario = new BLValcomplementario(parent.getConf());

        utilDepreciacion = new UtilDepreciacion(parent.getConf());

        personalizaVistaTabla();

        _init();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jCalendar1 = new com.toedter.calendar.JCalendar();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtComplementarioAsignado = new javax.swing.JTable();
        jbQuitar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        txfBuscar = new javax.swing.JTextField();
        jbBuscar = new javax.swing.JButton();
        jbCargarComplementario = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtComplementario = new javax.swing.JTable();
        jbAgregarComplementario = new javax.swing.JButton();
        jbSalir = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();
        jbGuardar = new javax.swing.JButton();
        jbAgregar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        txfPorcentajeDerecho = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jcbConsiderarPD = new javax.swing.JCheckBox();
        txfAdicional = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        txfValorTotal = new javax.swing.JTextField();
        jbCalcular = new javax.swing.JButton();
        jcbConsiderarVA = new javax.swing.JCheckBox();
        jLabel9 = new javax.swing.JLabel();
        txfNombre = new javax.swing.JTextField();
        jlUnidad = new javax.swing.JLabel();
        txfMedida = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jcbCategoria = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jcbAntiguedad = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jcbMaterial = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jcbEstado = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jcbValorEstado = new javax.swing.JComboBox();
        jbAgregarDepreciacion = new javax.swing.JButton();
        txfValorEstado = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setTitle("VALUACIÓN COMPLEMENTARIA");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "ASIGNACIÓN DE VALORES COMPLEMENTARIOS", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jtComplementarioAsignado.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null}
            },
            new String [] {
                "Title 1"
            }
        ));
        jScrollPane1.setViewportView(jtComplementarioAsignado);

        jbQuitar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ing/sisval/imagen/small_cancelar.png"))); // NOI18N
        jbQuitar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbQuitarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jbQuitar))
            .addComponent(jScrollPane1)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jbQuitar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "VALORES COMPLEMENTARIOS", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jbBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ing/sisval/imagen/small_buscar.png"))); // NOI18N
        jbBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBuscarActionPerformed(evt);
            }
        });

        jbCargarComplementario.setText("Cargar");
        jbCargarComplementario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCargarComplementarioActionPerformed(evt);
            }
        });

        jtComplementario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jtComplementario);

        jbAgregarComplementario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ing/sisval/imagen/small_agregar.png"))); // NOI18N
        jbAgregarComplementario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAgregarComplementarioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(txfBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 992, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbBuscar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbCargarComplementario)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbAgregarComplementario)
                .addGap(0, 0, Short.MAX_VALUE))
            .addComponent(jScrollPane2)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbBuscar)
                    .addComponent(jbCargarComplementario)
                    .addComponent(txfBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbAgregarComplementario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE))
        );

        jbSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ing/sisval/imagen/exit_min.png"))); // NOI18N
        jbSalir.setText("SALIR");
        jbSalir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbSalir.setVerifyInputWhenFocusTarget(false);
        jbSalir.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbSalir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbSalirActionPerformed(evt);
            }
        });

        jbCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ing/sisval/imagen/Cancelar_Min.png"))); // NOI18N
        jbCancelar.setText("CANCELAR");
        jbCancelar.setEnabled(false);
        jbCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbCancelar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });

        jbGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ing/sisval/imagen/big_guardar.png"))); // NOI18N
        jbGuardar.setText("GUARDAR");
        jbGuardar.setEnabled(false);
        jbGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbGuardar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        jbAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ing/sisval/imagen/Nuevo.png"))); // NOI18N
        jbAgregar.setText("AGREGAR");
        jbAgregar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbAgregar.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jbAgregar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jbAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAgregarActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "VALORIZACION", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jLabel2.setText("Procentaje de derechos (%) :");

        jcbConsiderarPD.setText("Considerar");
        jcbConsiderarPD.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbConsiderarPDActionPerformed(evt);
            }
        });
        jcbConsiderarPD.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jcbConsiderarPDPropertyChange(evt);
            }
        });

        jLabel3.setText("Valor adicional (S/.) :");

        jLabel1.setText("Valor Total (S/.) :");

        txfValorTotal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txfValorTotalActionPerformed(evt);
            }
        });

        jbCalcular.setText("Calcular");
        jbCalcular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCalcularActionPerformed(evt);
            }
        });

        jcbConsiderarVA.setText("Considerar");
        jcbConsiderarVA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbConsiderarVAActionPerformed(evt);
            }
        });
        jcbConsiderarVA.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jcbConsiderarVAPropertyChange(evt);
            }
        });

        jLabel9.setText("Nombre de obra complementaria :");

        txfNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txfNombreActionPerformed(evt);
            }
        });

        jlUnidad.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jlUnidad.setText("Área (m²) :");
        jlUnidad.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);

        txfMedida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txfMedidaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel1)
                    .addComponent(jlUnidad, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(txfMedida, javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addComponent(txfPorcentajeDerecho, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jcbConsiderarPD))
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addComponent(txfAdicional, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jcbConsiderarVA))
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addComponent(txfValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jbCalcular, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(txfNombre))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txfNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txfMedida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlUnidad))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txfPorcentajeDerecho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jcbConsiderarPD))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txfAdicional, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jcbConsiderarVA))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txfValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jbCalcular))
                .addGap(0, 0, 0))
        );

        jlUnidad.getAccessibleContext().setAccessibleName("");

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DEPRECIACIÓN", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        jLabel4.setText("Categoría :");

        jcbCategoria.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbCategoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbCategoriaActionPerformed(evt);
            }
        });

        jLabel5.setText("Antiguedad :");

        jcbAntiguedad.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbAntiguedad.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbAntiguedadActionPerformed(evt);
            }
        });

        jLabel6.setText("Material :");

        jcbMaterial.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbMaterial.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbMaterialActionPerformed(evt);
            }
        });

        jLabel7.setText("Estado :");

        jcbEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbEstado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbEstadoActionPerformed(evt);
            }
        });

        jLabel8.setText("Valor  :");

        jcbValorEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbValorEstado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcbValorEstadoActionPerformed(evt);
            }
        });

        jbAgregarDepreciacion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ing/sisval/imagen/small_agregar.png"))); // NOI18N
        jbAgregarDepreciacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAgregarDepreciacionActionPerformed(evt);
            }
        });

        jLabel10.setText("* En caso de que no exista el valor en la tabla.");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel4)
                    .addComponent(jLabel6)
                    .addComponent(jLabel8)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(txfValorEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jcbCategoria, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jcbAntiguedad, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jcbMaterial, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jcbEstado, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jcbValorEstado, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbAgregarDepreciacion)))
                .addGap(5, 5, 5))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jcbCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbAntiguedad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbMaterial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jcbValorEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel8))
                    .addComponent(jbAgregarDepreciacion))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txfValorEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jbAgregar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbGuardar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbCancelar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbSalir)
                        .addGap(64, 64, 64))))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jbAgregar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbCancelar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbGuardar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jbSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 8, Short.MAX_VALUE))
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSalirActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_jbSalirActionPerformed

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
        // TODO add your handling code here:
        _resetControls();
    }//GEN-LAST:event_jbCancelarActionPerformed

    private void txfValorTotalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txfValorTotalActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txfValorTotalActionPerformed

    private void jbQuitarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbQuitarActionPerformed
        // TODO add your handling code here:
        try {
            if (jtComplementarioAsignado.getSelectedRow() >= 0) {
                modeloComplementarioAsignado.remove(jtComplementarioAsignado.getSelectedRow());
                jlUnidad.setText("");
            } else {
                JOptionPane.showMessageDialog(this, "Seleccione el elemento a eliminar.", "Atención.", JOptionPane.INFORMATION_MESSAGE);

            }
        } catch (Exception e) {
            Logger.getLogger(JIFValuacionEdificacion.class.getName()).log(Level.SEVERE, null, e);
        }
        personalizaVistaTabla();
    }//GEN-LAST:event_jbQuitarActionPerformed

    private void jbCargarComplementarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCargarComplementarioActionPerformed
        // TODO add your handling code here:
        if (jtComplementario.getSelectedRow() >= 0) {
            agregarUnitario(modeloComplementario.get(jtComplementario.getSelectedRow()));
        } else {
            JOptionPane.showMessageDialog(this, "Seleccione un valor complementario de la tabla.", "Atención.", JOptionPane.INFORMATION_MESSAGE);
        }
        personalizaVistaTabla();
    }//GEN-LAST:event_jbCargarComplementarioActionPerformed

    private void jbCalcularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCalcularActionPerformed
        // TODO add your handling code here:
        if (!txfValorEstado.getText().isEmpty() && modeloComplementarioAsignado.size() > 0 && !txfMedida.getText().isEmpty()) {
            Double vu = sumaComplementario();
            double medida = Double.parseDouble(txfMedida.getText());
            double depreciacion = Double.parseDouble(txfValorEstado.getText());
            double total = 0.0;

            if (jcbConsiderarVA.isSelected()) {
                Double adicional = Double.parseDouble(txfAdicional.getText());
                if (jcbConsiderarPD.isSelected()) {
                    Double pd = Double.parseDouble(txfPorcentajeDerecho.getText()) / 100;
                    total = redondear((vu + adicional) * medida * pd * depreciacion);
                } else {
                    total = redondear((vu + adicional) * depreciacion * medida);
                }
            } else {
                if (jcbConsiderarPD.isSelected()) {
                    Double pd = Double.parseDouble(txfPorcentajeDerecho.getText()) / 100;
                    total = redondear(vu * medida * pd * depreciacion);
                } else {
                    total = redondear(vu * medida * depreciacion);
                }

            }
            txfValorTotal.setText(Double.toString(redondear(total)));
        } else {
            JOptionPane.showMessageDialog(this, "Complete todos los campos.", "Atención", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jbCalcularActionPerformed

    private void jcbConsiderarPDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbConsiderarPDActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jcbConsiderarPDActionPerformed

    private void jcbCategoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbCategoriaActionPerformed
        // TODO add your handling code here:
        eventoComboCategoria();
    }//GEN-LAST:event_jcbCategoriaActionPerformed

    private void jcbAntiguedadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbAntiguedadActionPerformed
        // TODO add your handling code here:
        eventoComboAntiguedad();
    }//GEN-LAST:event_jcbAntiguedadActionPerformed

    private void jcbMaterialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbMaterialActionPerformed
        // TODO add your handling code here:
        eventoComboMaterial();
    }//GEN-LAST:event_jcbMaterialActionPerformed

    private void jcbEstadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbEstadoActionPerformed
        // TODO add your handling code here:
        eventoComboEstado();
    }//GEN-LAST:event_jcbEstadoActionPerformed

    private void jcbValorEstadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbValorEstadoActionPerformed
        // TODO add your handling code here:
        eventoComboValorEstado();
    }//GEN-LAST:event_jcbValorEstadoActionPerformed

    private void jbBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBuscarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jbBuscarActionPerformed

    private void jbAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAgregarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jbAgregarActionPerformed

    private void jbAgregarComplementarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAgregarComplementarioActionPerformed
        // TODO add your handling code here:
        parent.insertarInternalFrame(parent.administrarComplementario);
    }//GEN-LAST:event_jbAgregarComplementarioActionPerformed

    private void jbAgregarDepreciacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAgregarDepreciacionActionPerformed
        // TODO add your handling code here:
        parent.insertarInternalFrame(parent.administrarDepreciacion);
    }//GEN-LAST:event_jbAgregarDepreciacionActionPerformed

    private void jcbConsiderarVAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbConsiderarVAActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jcbConsiderarVAActionPerformed

    private void jcbConsiderarPDPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jcbConsiderarPDPropertyChange
        // TODO add your handling code here:
        if (jcbConsiderarPD.isSelected()) {
            txfPorcentajeDerecho.setEnabled(true);
        } else {
            txfPorcentajeDerecho.setText("");
            txfPorcentajeDerecho.setEnabled(false);
        }

    }//GEN-LAST:event_jcbConsiderarPDPropertyChange

    private void jcbConsiderarVAPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jcbConsiderarVAPropertyChange
        // TODO add your handling code here:
        if (jcbConsiderarVA.isSelected()) {
            txfAdicional.setEnabled(true);
        } else {
            txfAdicional.setText("");
            txfAdicional.setEnabled(false);
        }
    }//GEN-LAST:event_jcbConsiderarVAPropertyChange

    private void txfNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txfNombreActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txfNombreActionPerformed

    private void txfMedidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txfMedidaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txfMedidaActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.toedter.calendar.JCalendar jCalendar1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbAgregar;
    private javax.swing.JButton jbAgregarComplementario;
    private javax.swing.JButton jbAgregarDepreciacion;
    private javax.swing.JButton jbBuscar;
    private javax.swing.JButton jbCalcular;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbCargarComplementario;
    private javax.swing.JButton jbGuardar;
    private javax.swing.JButton jbQuitar;
    private javax.swing.JButton jbSalir;
    private javax.swing.JComboBox jcbAntiguedad;
    private javax.swing.JComboBox jcbCategoria;
    private javax.swing.JCheckBox jcbConsiderarPD;
    private javax.swing.JCheckBox jcbConsiderarVA;
    private javax.swing.JComboBox jcbEstado;
    private javax.swing.JComboBox jcbMaterial;
    private javax.swing.JComboBox jcbValorEstado;
    private javax.swing.JLabel jlUnidad;
    private javax.swing.JTable jtComplementario;
    private javax.swing.JTable jtComplementarioAsignado;
    private javax.swing.JTextField txfAdicional;
    private javax.swing.JTextField txfBuscar;
    private javax.swing.JTextField txfMedida;
    private javax.swing.JTextField txfNombre;
    private javax.swing.JTextField txfPorcentajeDerecho;
    private javax.swing.JTextField txfValorEstado;
    private javax.swing.JTextField txfValorTotal;
    // End of variables declaration//GEN-END:variables
    @Override
    public void _cargarCombos() throws Exception {
        utilDepreciacion.defaultSelectedDepreciacion("", "", "", "", 0, jcbCategoria, jcbAntiguedad, jcbMaterial, jcbEstado, jcbValorEstado);

    }

    @Override
    public void _agregaValidadoresControl() {
        addEnterDoclickEvent(new Object[][]{{txfBuscar, jbBuscar}});
        _addOperationEventsButtons(jbAgregar, jbGuardar, jbCancelar);
        _addRestoreDataEventsTable(jtComplementario);
        _addSearchEventsButton(jbBuscar);
        addCharacterValidatorEvent(new Object[][]{ // {txfAreaTechada, NUMERICO, 20},
            {txfAdicional, Utilitarios.NUMERICO_REAL, 180},
            {txfPorcentajeDerecho, Utilitarios.NUMERICO_REAL, 180},
            {txfNombre, Utilitarios.ALFABETICO_CM, 180},
            {txfMedida, Utilitarios.NUMERICO_REAL, 20},});
    }

    @Override
    public boolean _isDatosValidosBE() {
        return Utilitarios.isDatosLlenos(new Object[][]{
            {txfNombre, "Ingresar el nombre de la obra complementaria"},
            {txfValorTotal, "Calcular el valor total de edificación con el botón 'calcular'"},
            {txfMedida, "Ingrese la medida en metros."},});
    }

    @Override
    public int _registrarBE() throws Exception {
        be = new BEValuacionComplementario();
        be.setValorTotal(Double.parseDouble(txfValorTotal.getText()));
        if (jcbValorEstado.getSelectedIndex() == 0) {
            be.setDepreciacionid(0);
        } else {
            be.setDepreciacionid(((BEDepreciacion) jcbValorEstado.getSelectedItem()).getDepreciacionid());
        }
        if (!txfPorcentajeDerecho.getText().isEmpty()) {
            be.setPorcentajeDerecho(Double.parseDouble(txfPorcentajeDerecho.getText()));
        } else {
            be.setPorcentajeDerecho(0.0);
        }
        if (!txfAdicional.getText().isEmpty()) {
            be.setValorAdicional(Double.parseDouble(txfAdicional.getText()));
        } else {
            be.setValorAdicional(0.0);
        }
        be.setNombre(txfNombre.getText());
        be.setMedida(Double.parseDouble(txfMedida.getText()));
        be.setValorEstado(Double.parseDouble(txfValorEstado.getText()));

        bl.registrar(be);

        int id = bl.obtenerUltimoId();

        for (BEComplementario s : modeloComplementarioAsignado.getList()) {
            beValcomplementario = new BEValcomplementario();
            beValcomplementario.setValuacioncomplementarioid(id);
            beValcomplementario.setComplementarioid(s.getComplementarioid());
            blValcomplementario.registrar(beValcomplementario);
        }

        JOptionPane.showMessageDialog(this, "Registro satisfactorio de valuacion complementario", "Registro Valuacion Complementario", JOptionPane.INFORMATION_MESSAGE);
        cargar();
        dispose();

        _resetControls();
        _deshabilitarControlesDatos();
        _listarBEs();
        return id;
    }

    @Override
    public int _guardarCambiosBE() throws Exception {
        be.setValorTotal(Double.parseDouble(txfValorTotal.getText()));

        be = new BEValuacionComplementario();
        be.setValorTotal(Double.parseDouble(txfValorTotal.getText()));
        if (jcbValorEstado.getSelectedIndex() == 0) {
            be.setDepreciacionid(0);
        } else {
            be.setDepreciacionid(((BEDepreciacion) jcbValorEstado.getSelectedItem()).getDepreciacionid());
        }
        if (!txfPorcentajeDerecho.getText().isEmpty()) {
            be.setPorcentajeDerecho(Double.parseDouble(txfPorcentajeDerecho.getText()));
        } else {
            be.setPorcentajeDerecho(0.0);
        }
        if (!txfAdicional.getText().isEmpty()) {
            be.setValorAdicional(Double.parseDouble(txfAdicional.getText()));
        } else {
            be.setValorAdicional(0.0);
        }
        be.setNombre(txfNombre.getText());
        be.setMedida(Double.parseDouble(txfMedida.getText()));
        be.setValorEstado(Double.parseDouble(txfValorEstado.getText()));

        int rsp = bl.actualizarRegistro(be);

        int idcomp = modeloComplementario.get(jtComplementario.getSelectedRow()).getComplementarioid();
        if (!blValcomplementario.listarAsignacion(idcomp).isEmpty()) {
            blValcomplementario.eliminarAsignacion(idcomp);

        }
        for (BEComplementario s : modeloComplementarioAsignado.getList()) {
            beValcomplementario = new BEValcomplementario();
            beValcomplementario.setValuacioncomplementarioid(idcomp);
            beValcomplementario.setComplementarioid(s.getComplementarioid());
            blValcomplementario.registrar(beValcomplementario);
        }

        _resetControls();
        _deshabilitarControlesDatos();
        _listarBEs();
        return rsp;
    }

    @Override
    public void _listarBEs() throws Exception {
        modeloComplementario.addAll(blComplementario.buscarReferencia(txfBuscar.getText()));
        personalizaVistaTabla();
    }

    @Override
    public void _recuperarDatosBE() throws Exception {

    }

    @Override
    public void _deshabilitarControlesDatos() {
        Utilitarios.disableComponent(new Object[]{
            txfValorTotal, jcbConsiderarVA, jcbConsiderarPD,
            jbCalcular, jtComplementarioAsignado,
            jbCargarComplementario, jbQuitar, jtComplementario,
            jcbCategoria, jcbAntiguedad, jcbMaterial, jcbEstado, jcbValorEstado,
            txfPorcentajeDerecho, txfAdicional, jbAgregarComplementario, jbAgregarDepreciacion,
            txfNombre, txfMedida, txfValorEstado
        });
    }

    @Override
    public void _habilitarControlesDatos() {
        Utilitarios.enableComponent(new Object[]{
            txfValorTotal, jcbConsiderarVA, jcbConsiderarPD,
            jbCalcular, jtComplementarioAsignado,
            jbCargarComplementario, jbQuitar, jtComplementario,
            jcbCategoria, jcbAntiguedad, jcbMaterial, jcbEstado, jcbValorEstado,
            txfPorcentajeDerecho, txfAdicional, jbAgregarComplementario, jbAgregarDepreciacion,
            txfNombre, txfMedida, txfValorEstado});
        txfValorTotal.setEditable(false);

        try {
            _listarBEs();

        } catch (Exception ex) {
            Logger.getLogger(JIFValuacionEdificacion.class.getName()).log(Level.SEVERE, null, ex);
        }
        personalizaVistaTabla();
    }

    @Override
    public void _resetControls() {
        Utilitarios.resetComponents(new Object[]{
            txfValorTotal, jcbConsiderarVA,
            jbCalcular, jtComplementarioAsignado, jcbConsiderarPD,
            jbCargarComplementario, jbQuitar, jtComplementario,
            jcbCategoria, jcbAntiguedad, jcbMaterial, jcbEstado, jcbValorEstado,
            txfPorcentajeDerecho, txfAdicional, jbAgregarComplementario, jbAgregarDepreciacion,
            txfNombre, txfMedida, txfValorEstado});
        txfValorTotal.setEditable(false);
        modeloComplementario.clear();
        modeloComplementarioAsignado.clear();
        jlUnidad.setText("");

    }

    private void personalizaVistaTabla() {
        alinearDatosColumnaTablaCentro(0, jtComplementario);
        alinearDatosColumnaTablaCentro(1, jtComplementario);
        alinearDatosColumnaTablaCentro(2, jtComplementario);
        alinearDatosColumnaTablaCentro(3, jtComplementario);
        formateaAnchoColumnaTabla(0, jtComplementario, 300);
        formateaAnchoColumnaTabla(1, jtComplementario, 700);
        formateaAnchoColumnaTabla(2, jtComplementario, 79);
        formateaAnchoColumnaTabla(3, jtComplementario, 75);

        alinearDatosColumnaTablaCentro(0, jtComplementarioAsignado);
        alinearDatosColumnaTablaCentro(1, jtComplementarioAsignado);
        alinearDatosColumnaTablaCentro(2, jtComplementarioAsignado);
        alinearDatosColumnaTablaCentro(3, jtComplementarioAsignado);
        formateaAnchoColumnaTabla(0, jtComplementarioAsignado, 300);
        formateaAnchoColumnaTabla(1, jtComplementarioAsignado, 700);
        formateaAnchoColumnaTabla(2, jtComplementarioAsignado, 79);
        formateaAnchoColumnaTabla(3, jtComplementarioAsignado, 100);
    }

    void agregarUnitario(BEComplementario componente) {
        try {
//            boolean c = false;
//            for (int i = 0; i < modeloComplementarioAsignado.getRowCount(); i++) {
//                if (modeloComplementarioAsignado.get(i).getComplementarioid() == componente.getComplementarioid()) {
//                    JOptionPane.showMessageDialog(this, "El valor complementario ha sido seleccionado anteriormente, por favor seleccione otro.", "Atención", JOptionPane.INFORMATION_MESSAGE);
//                    c = true;
//                }
//            }
//            if (c == false) {
            modeloComplementarioAsignado.clear();
            modeloComplementarioAsignado.add(componente);
            //cargar unidad
            switch (componente.getUnidadmedida().toString()) {
                case "m2":
                    jlUnidad.setText("Área (m²) :");
                    break;
                case "m3":
                    jlUnidad.setText("Volumen (m3) :");
                    break;
                case "und":
                    jlUnidad.setText("Unidad (und) :");
                    break;
                case "ml":
                    jlUnidad.setText("Mililitro (ml) :");
                    break;
                case "pza":
                    jlUnidad.setText("Pieza (pza) :");
                    break;
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error al asignar valor complementario", "Atención", JOptionPane.INFORMATION_MESSAGE);
        }
    }

    public Double sumaComplementario() {
        Double suma = 0.0;
        for (BEComplementario s : modeloComplementarioAsignado.getList()) {
            suma = suma + s.getValorunitario();
        }
        return suma;
    }

    public void eventoComboCategoria() {
        if (utilDepreciacion != null && jcbCategoria.getSelectedIndex() > 0) {
            utilDepreciacion.eventoComboCategoria(jcbCategoria, jcbAntiguedad, jcbMaterial, jcbEstado, jcbValorEstado);
        }
    }

    public void eventoComboAntiguedad() {
        if (utilDepreciacion != null && jcbAntiguedad.getSelectedIndex() > 0) {
            utilDepreciacion.eventoComboAntiguedad(jcbCategoria, jcbAntiguedad, jcbMaterial, jcbEstado, jcbValorEstado);
        }
    }

    public void eventoComboMaterial() {
        if (utilDepreciacion != null && jcbMaterial.getSelectedIndex() > 0) {
            utilDepreciacion.eventoComboMaterial(jcbCategoria, jcbAntiguedad, jcbMaterial, jcbEstado, jcbValorEstado);
        }
    }

    public void eventoComboEstado() {
        if (utilDepreciacion != null && jcbEstado.getSelectedIndex() > 0) {
            utilDepreciacion.eventoComboEstado(jcbCategoria, jcbAntiguedad, jcbMaterial, jcbEstado, jcbValorEstado);
            if (jcbValorEstado.getModel().getSize() > 0) {
                jcbValorEstado.setSelectedIndex(1);
                txfValorEstado.setText(jcbValorEstado.getSelectedItem().toString());
            }
        }

    }

    public void eventoComboValorEstado() {
        if (utilDepreciacion != null && jcbValorEstado.getSelectedIndex() > 0) {
            utilDepreciacion.eventoComboValorEstado(jcbCategoria, jcbAntiguedad, jcbMaterial, jcbEstado, jcbValorEstado);
        }
    }

    public void cargar() {

        BEValuacionComplementario bevc;
        try {
            bevc = bl.buscar(bl.obtenerUltimoId());
            System.out.println("Este es el id de complementario : " + bl.obtenerUltimoId());

            parent.administrarPropiedad.agregarComplementario(bevc);

        } catch (Exception ex) {
            Logger.getLogger(JIFValuacionTerreno.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public double redondear(double numero) {
        BigDecimal big = new BigDecimal(numero);
        big = big.setScale(2, RoundingMode.HALF_UP);
        System.out.println("Este es el valor redondeado :" + new Double(big.toString()));
        return new Double(big.toString());
    }
}
